package com.centaur0.util;

import javax.servlet.ServletContext;

import org.springframework.context.ApplicationContext;
import org.springframework.context.i18n.LocaleContextHolder;

public abstract class Application {

	public static final String USER_HTTP_SESSION = "user.http.session";
	public static final String SECURITY_AUTENTICATORVERIFIER = "application.security.autenticationVerifier";
	private static ApplicationContext springCtx;
	private static ServletContext httpApplicationContext;

	@SuppressWarnings("unchecked")
	public static <T> T getResource(String beanName) {
		try{
			return (T)springCtx.getBean(beanName);
		} catch(Exception e){
			if(springCtx.getParent() != null){
				try{
					return (T) springCtx.getParent().getBean(beanName);
				} catch(Exception e2){}
			}
			return null;
		}
	}
	public static void setApplicationContext(ApplicationContext ctx) {
		springCtx = ctx; 
	}
	public static ServletContext getHttpApplicationContext() {
		return httpApplicationContext;
	}
	
	public static void setHttpApplicationContext(ServletContext httpApplicationContext) {
		Application.httpApplicationContext = httpApplicationContext;
	}
	public static String getMessage(String code) {
		return springCtx.getMessage(code, null, LocaleContextHolder.getLocale());
	}
}
